package com.zly.android.architectural.pattern.mvvm

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.ViewModelProvider
import com.zly.android.architectural.pattern.databinding.ActivityMainBinding

/**
 * MVVM:单向依赖 View依赖ViewModel，ViewModel依赖Model的单向依赖
 * Model:通过观察者模式通知数据，MVP是接口回调
 * View:可视化处理，与viewmodel交互
 * viewmodel:发起请求，与mvp相比，不依赖view
 */
class MvvmActivity:BaseActivity<ActivityMainBinding,MyViewModel>() {
    var myViewModel:MyViewModel?=null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        myViewModel=ViewModelProvider(this)[MyViewModel::class.java]
    }

    override fun setBinding(): ActivityMainBinding {
        return ActivityMainBinding.inflate(layoutInflater)
    }

    override fun setViewModel(): MyViewModel {
        return MyViewModel()
    }
}